package cn.gjxblog.modules.third.oss;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Author guojiaxun
 * @Date 2019/9/17 13:58
 */

public enum OssTypeEnum{
    Qiniu("qiniuCloudServiceImpl", 1),
    Aliyun("aliyunCloudServiceImpl", 2);

    String name;
    Integer type;



    private String getName() {
        return name;
    }


    public Integer type() {
        return type;
    }

    OssTypeEnum(String name, Integer type) {
        this.name = name;
        this.type = type;
    }

    public static String getNameByType(Integer type){
        Optional<OssTypeEnum> optional = Arrays.stream(OssTypeEnum.values())
                .filter(ossTypeEnum -> ossTypeEnum.type().equals(type))
                .findFirst();
        return optional.map(OssTypeEnum::getName).orElse(null);
    }

    public static Integer geTypeByName(String name){
        Optional<OssTypeEnum> optional = Arrays.stream(OssTypeEnum.values())
                .filter(ossTypeEnum -> ossTypeEnum.getName().equals(name))
                .findFirst();
        return optional.map(OssTypeEnum::type).orElse(null);
    }
}